package com.example.star.controller;

import com.example.star.entity.Message;
import com.example.star.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @GetMapping("/messages/{starName}")
    public List<Message> getMessagesByStarName(@PathVariable String starName) {
        return messageService.getMessagesByStarName(starName);
    }

    @GetMapping("/allMessages/{starName}")
    public List<Message> getAllMessagesByStarName(@PathVariable String starName) {
        return messageService.getAllMessagesByStarName(starName);
    }

    @PostMapping("/sendMessage")
    public void sendMessage(@RequestBody Message message) {
        messageService.saveMessage(message);
    }
    @GetMapping("/user/{userName}")
    public List<Message> getUserMessages(@PathVariable String userName) {
        return messageService.getUserMessages(userName);
    }
}
